<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"  %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<rapid:override name="frame-header-style">
 	<link rel="stylesheet" href="static/plugin/layui/css/layui.css">
    <link rel="stylesheet" href="static/css/back.css">
    <link rel="stylesheet" href="static/plugin/font-awesome/css/font-awesome.min.css">
    <style>
        /*覆盖 layui*/
        .layui-input-block {
            margin:0px 10px;
        }
        .layui-table {
            margin-top: 0;
        }
        .layui-col-md4 {
            padding:10px;
        }
        .layui-col-md8 {
            padding:10px;
        }
        .layui-btn {
            margin: 2px 0!important;
        }
    </style>
</rapid:override>
<rapid:override name="frame-header-script">
<script src="static/js/jquery.min.js"></script>
<script>

//用来检测分类名是否重复
function checkCategoryName() {
  var result=false;
  if($("#categoryName").val()==null||$("#categoryName").val()==""){
	  $("#categoryName_msg").html("分类名不能为空！").css("color","red");
  }
  else{
  $.ajax({
      async: false,//同步，待请求完毕后再执行后面的代码
      type: "POST",
      url: 'category/checkCategoryName',
      //contentType: "application/x-www-form-urlencoded; charset=utf-8",
      data: {"categoryName": $("#categoryName").val()},
      success: function (data) {
      	
          //用户名存在
          if(data==1) {
              $("#categoryName_msg").html("分类名重复，请重新输入！").css("color","red");
              result=false;
          }
          //用户名不存在
          if(data==0) {
              $("#categoryName_msg").html("分类名可用").css("color","green");
              result=true;
          }
      },
  })}
  return result;
}
function checkAll(){
	var result =checkCategoryName();
	return result;
}
</script>
</rapid:override>
<rapid:override name="frame-content">
        <div style="padding:15px;">
            <blockquote class="layui-elem-quote">
				        <span class="layui-breadcrumb" lay-separator="/">
				              <a href="/admin">首页</a>
				              <a href="/admin/category">分类列表</a>
				              <a><cite>分类修改</cite></a>
				        </span>
				    </blockquote>
   
    
    <div class="layui-row">
        <div class="layui-col-md4">
            <form class="layui-form"  method="post" id="myForm" action="category/updateCategory">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <strong>分类修改</strong>
                    </div>
                    <div class="layui-input-block">
                    <input type="hidden" name="categoryId" value="${category.categoryId }" />
                        名称 <span style="color: #FF5722; ">*</span>
                        <input type="text" name="categoryName" id="categoryName" placeholder="请输入分类名称" onblur="checkCategoryName()" autocomplete="off" class="layui-input"  required value="${category.categoryName}"><label  id="categoryName_msg"  ></label>
                    </div>
                    <br>
                    <div class="layui-input-block">
                        父节点 <span style="color: #FF5722; ">*</span>
                        <select name="categoryPid" id="categoryPid" class="layui-input" required>
                            	<option value="0">无</option>
                            	<c:forEach var="n" items="${parentCategoryList}">
                            	  <c:choose>
                            	 <c:when test="${n.categoryId==category.categoryPid}">
									<option value="${n.categoryId}"  selected>${n.categoryName}</option>
								</c:when>
								<c:otherwise>
                           			<option value="${n.categoryId}">${n.categoryName}</option>
                           		</c:otherwise> 
                           		 </c:choose>
                                </c:forEach>
                         </select>
                    </div>
                    <br>
                    <div class="layui-input-block">
                        分类描述
                        <input type="text" name="categoryDescription" placeholder="请输入分类描述" autocomplete="off" class="layui-input"  value="${category.categoryDescription}">
                    </div>
                    <br>
                    <div class="layui-input-block">
                        图标样式
                        <input type="text" name="categoryIcon" placeholder="请输入图标样式,如 fa fa-coffee" autocomplete="off" class="layui-input"  value="${category.categoryIcon}">
                    </div>
                    <br>
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-filter="formDemo" type="submit" onclick="return checkAll()">修改</button> ${msg }
                    </div>
                    
                </div>
            </form>
        </div>
    </div>
</div>

</rapid:override>
<rapid:override name="frame-footer-script">
<script>



</script>
</rapid:override>
<%@ include file="../framework.jsp" %>